﻿#region Copyright (c) 2012-11, Olaf Kober <amarok.projects@gmail.com>
//================================================================================
//	Permission is hereby granted, free of charge, to any person obtaining a copy
//	of this software and associated documentation files (the "Software"), to deal
//	in the Software without restriction, including without limitation the rights
//	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//	copies of the Software, and to permit persons to whom the Software is
//	furnished to do so, subject to the following conditions:
//
//	The above copyright notice and this permission notice shall be included in
//	all copies or substantial portions of the Software.
//
//	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//	THE SOFTWARE.
//================================================================================
#endregion

#if TESTS

using System;
using NUnit.Framework;


namespace Amarok.Agents
{
	[TestFixture]
	public class Test_InformationHandlerAttribute
	{
		private abstract class MyBaseClass
		{
			[InformationHandler]
			public abstract void TestMethod3();

			public abstract void TestMethod4();
		}

		private class MyClass : MyBaseClass
		{
			public void TestMethod1()
			{
			}

			[InformationHandler]
			public void TestMethod2()
			{
			}

			public override void TestMethod3()
			{
			}

			[InformationHandler]
			public override void TestMethod4()
			{
			}
		}


		// --- TESTS ---


		[Test]
		public void Test_IsDefined()
		{
			var target = new MyClass();
			var targetType = target.GetType();
			var method1 = targetType.GetMethod("TestMethod1");
			var method2 = targetType.GetMethod("TestMethod2");
			var method3 = targetType.GetMethod("TestMethod3");
			var method4 = targetType.GetMethod("TestMethod4");

			Assert.That(method1, Is.Not.Null);
			Assert.That(method2, Is.Not.Null);
			Assert.That(method3, Is.Not.Null);
			Assert.That(method4, Is.Not.Null);

			Assert.That(InformationHandlerAttribute.IsDefined(method1), Is.False);
			Assert.That(InformationHandlerAttribute.IsDefined(method2), Is.True);
			Assert.That(InformationHandlerAttribute.IsDefined(method3), Is.True);
			Assert.That(InformationHandlerAttribute.IsDefined(method4), Is.True);
		}

		[Test]
		public void Test_IsDefined_NullMethod()
		{
			Assert.Throws<ArgumentNullException>(() =>
				InformationHandlerAttribute.IsDefined(null));
		}

	}
}

#endif
